import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
from datetime import datetime, timedelta

# 定义时间范围
start_date = datetime(2023, 1, 1)
end_date = datetime(2023, 12, 31)
num_hours = (end_date - start_date).days * 24  # 总小时数

# 生成时间戳
timestamps = [start_date + timedelta(hours=i) for i in range(num_hours)]

# 生成递减的放射性物质浓度数据
initial_concentration = 1.0  # 初始浓度
decay_rate = 0.00002  # 递减速率的初始值
min_concentration = 0.25  # 永不为零的最小浓度

concentrations = []

for i in range(num_hours):
    concentration = initial_concentration * np.exp(-decay_rate * i)
    if concentration < min_concentration:
        concentration = min_concentration
    concentrations.append(concentration)
    # 递减速率逐渐变慢
    decay_rate *= 1.0002  # 可根据需求调整递减速率的变化程度

# 创建数据框
data = pd.DataFrame({
    'timestamp': timestamps,
    'concentration': concentrations
})

# 保存数据到 CSV 文件
data.to_csv('data_resource\\radiation_data.csv', index=False)
# 读取CSV文件
data = pd.read_csv('data_resource\\radiation_data.csv')
# 转换时间列为日期时间格式
data['timestamp'] = pd.to_datetime(data['timestamp'])
# print(data['timestamp'])
# print(data['concentration'])
# 绘制放射性物质浓度随时间的变化
plt.figure(figsize=(10, 6))
plt.plot(data['timestamp'], data['concentration'], marker='o')
plt.xlabel('time')
plt.ylabel('Concentration of radioactive material')
plt.title('Radioactive material concentration changes')
plt.xticks(rotation=45)
plt.grid(True)
plt.show()